var point = "<div style='width:15px;height:15px;background-color:rgb(225,103,0);color:#fff;font-weight:bold;border-radius:25px;line-height:15px;text-align:center;float:left;margin:0 4px 0 -6px;'>!</div>";

var flag1 = 0;
var flag2 = 0;
var result ="";
var phone ="";

function testPhone(){
   var Str =  document.getElementById("outpng");
   var pbox = document.getElementById("pid");
   phone = pbox.value;
   var textpid = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
   var massge =  document.getElementById("s1");
   if(phone.length == 0){
	   pbox.style.border = "1px solid rgb(255,103,0)";
	   massge.innerHTML = point+"电话号码不能为空"; 
	   Str.style.top=73;
   }else if(!textpid.test(phone)){
	    pbox.style.border = "1px solid rgb(255,103,0)";
	    massge.innerHTML = point+"电话号码格式有误"; 
		Str.style.top=73;
   }else{
	   pbox.style.border = "1px solid rgb(169,169,169)";
	   massge.innerHTML = ""; 
	   Str.style.top=58;
	   flag1 = 1;
   }
}

function clearMassge(id){
	var massge =  document.getElementById(id);
	massge.innerHTML = ""; 
	if(id=="s1"){
	  document.getElementById("pid").style.border = "1px solid rgb(169,169,169)";
	  document.getElementById("outpng").style.top=58;
	}else{
		document.getElementById("png").style.border = "1px solid rgb(169,169,169)";
	}
}

function testPng(){
   var pngbox = document.getElementById("png");
   var png = pngbox.value;
   var massge =  document.getElementById("s2");
   if(png.length == 0){
	   pngbox.style.border = "1px solid rgb(255,103,0)";
	   massge.innerHTML = point+"请输入图片验证码"; 
   }else{
	   flag2 = 1;
   }
   if(result.toLocaleLowerCase() != png.toLocaleLowerCase()){
	   pngbox.style.border = "1px solid rgb(255,103,0)";
	   massge.innerHTML = point+"验证码错误"; 
   }else{
	   flag2 = 1;
	   massge.innerHTML = ""; 
	    pngbox.style.border = "1px solid rgb(169,169,169)";
   } 
}

function changeCode(){
	result = "";
	var codes = new Array(
	   'abcdefghijklmnopqrstuvwxyz', 
       'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
       '0123456789'
	);
	var colors = new Array('#F0F8FF','#FAEBD7','#FFE4C4','#8A2BE2','#5F9EA0','#FF7F50','#DC143C',
		                   '#9932CC','#DCDCDC','#DAA520','#4B0082','#FFF0F5','#F08080','#32CD32', 
						   '#9ACD32','#EE82EE','#008080','#C0C0C0','#DA70D6','#EEE8AA','#FF4500'
	);
	var sizes = new Array('14px','16px','18px','20px','24px','28px','32px');
	var jpgs = new Array('code1.png','code2.png','code3.png','code4.png','code5.png',
	                     'code6.png','code7.png','code8.png','code9.png','code10.png');
	var tempStr = "";
	for(var i=0;i<5;i++){
	    var index = Math.floor(Math.random()*3);
		var color = Math.floor(Math.random()*21);
		var size = Math.floor(Math.random()*7);
		var temp = codes[index].substr(Math.floor(Math.random()*(codes[index].length)), 1);
		result += temp;
        tempStr += "<span style='color:"+colors[color]+";font-size:"+sizes[size]+";font-weight:bold;-webkit-transform:rotate(7deg);'>"+temp+"</span>";
	}
	
	var code = document.getElementById("code");
	var content = document.getElementById("content");
	
	code.style.background = "url("+jpgs[Math.floor(Math.random()*10)]+")";
	content.innerHTML =  tempStr ;
}

function checkMassge(){	
   	if(flag1==1 && flag2==1){
   		alert("regist");
		window.location.href = "registPhone.html";
	}
}